package java6681.lesson09;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author Junichiro
 * @description
 * @date 2021-05-08 21:04
 **/

public class ReadFile6681Controller {

    @FXML
    private TextField tfFilename;

    @FXML
    private TextArea taText;

    @FXML
    void readFile() {
        String text = tfFilename.getText();
        File file = new File(text);
        byte[] data = new byte[1024];
        int len = 0;
        try (FileInputStream in = new FileInputStream(file)){
            len = in.read(data);
            taText.setText(new String(data,0,len));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

